package org.example.v1;

public class OrderStateMachine {
    private OrderState state;

    public OrderStateMachine() {
        this.state = OrderState.PENDING;
    }

    public void onEvent(String event) {
        switch (state) {
            case PENDING:
                if (event.equals("pay")) {
                    state = OrderState.PAID;
                }
                break;
            case PAID:
                if (event.equals("ship")) {
                    state = OrderState.SHIPPED;
                }
                break;
            case SHIPPED:
                if (event.equals("deliver")) {
                    state = OrderState.DELIVERED;
                }
                break;
            case DELIVERED:
                System.out.println("Order is already delivered. No further action is possible.");
                break;
            default:
                throw new IllegalStateException("Unexpected state: " + state);
        }
    }

    @Override
    public String toString() {
        return "Order is currently " + state;
    }
}
